/*-*
 * FILENAME  :
 *    $HeadURL$
 *
 * STATUS  :
 *    $Revision$
 *
 *    $Author$
 *    $Date$
 *  
 *    
 * Copyright (c) 2011 Gonalge Ltda. All rights reserved.
 *
 ****************************************************************/

package org.gonalge.arbolrojonegro.presentacion;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;

import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.gonalge.arbolrojonegro.util.FormUtils;

/**
 * 
 * @author Geremias Gonzalez
 */
public class FormRojoNegro extends JFrame {
    /**
     * 
     */
    private static final long serialVersionUID = -5313084796346836079L;

    private final JButton concepto = new JButton();

    private final JButton practica = new JButton();

    private final JButton evaluacion = new JButton();

    private final JLabel titulo = new JLabel();

    private final JButton salir = new JButton();

    private final PintarFractal fractalIzq = new PintarFractal(90);

    private final PintarFractal fractalDer = new PintarFractal(90);

    private final FormConcepto conceptoForm = new FormConcepto();

    private final FormPractica practicaForm = new FormPractica();

    private final FormEvaluacion evaluaionForm = new FormEvaluacion();

    private final Timer tiempo = new Timer(800, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            fractalIzq.pintar();
            fractalDer.pintar();
        }
    });

    public FormRojoNegro() {
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.setTitle("Tutor Arbol Rojo y Negro");
        this.setResizable(false);
        this.getContentPane().setLayout(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.getContentPane().setBackground(FormUtils.getColorFondo());
        this.setBounds(FormUtils.crearRectangle(this));

        fractalIzq.setBounds(50, 250, 250, 300);
        fractalDer.setBounds(780, 250, 250, 300);

        titulo.setIcon(FormUtils.getImageIcon(getClass(), "titulo"));
        titulo.setBounds(new Rectangle(160, 50, titulo.getIcon().getIconWidth(), titulo.getIcon().getIconHeight()));

        FormUtils.updateButton(getClass(), concepto, "concepto1", "concepto2", 300, 280);
        concepto.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                conceptoForm.setVisible(true);
            }
        });

        FormUtils.updateButton(getClass(), practica, "practica1", "practica2", 370, 390);
        practica.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                practicaForm.setVisible(true);
            }
        });

        FormUtils.updateButton(getClass(), evaluacion, "evaluacion1", "evaluacion2", 440, 500);
        evaluacion.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                evaluaionForm.setVisible(true);
            }
        });

        FormUtils.updateButton(getClass(), salir, "salir1", "salir2", 890, 630);
        salir.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        this.getContentPane().add(salir);
        this.getContentPane().add(fractalIzq);
        this.getContentPane().add(fractalDer);
        this.getContentPane().add(titulo);
        this.getContentPane().add(concepto);
        this.getContentPane().add(practica);
        this.getContentPane().add(evaluacion);
        tiempo.start();
    }

    public static void main(String agr[]) {
        FormRojoNegro frmRojoNegro = new FormRojoNegro();
        frmRojoNegro.setVisible(true);
    }
}
